/* GUI CONVERTED from gppibx.p (converter v1.76) Thu Apr 25 18:58:59 2002 */
/* gppibx.p - The very best in Pricing subroutines                            */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.15 $                                                          */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 8.5      LAST MODIFIED: 12/27/95   BY: afs *J042*                */
/* REVISION: 8.5      LAST MODIFIED: 07/28/95   BY: DAH *J063*                */
/* REVISION: 8.5      LAST MODIFIED: 02/09/96   BY: DAH *J0CQ*                */
/* REVISION: 8.5      LAST MODIFIED: 04/03/96   BY: DAH *J0GT*                */
/* REVISION: 8.5      LAST MODIFIED: 07/05/96   BY: DAH *J0XR*                */
/* REVISION: 8.5      LAST MODIFIED: 07/22/96   BY: *J0ZW* Dennis Henson      */
/* REVISION: 8.6E     LAST MODIFIED: 05/09/98   BY: *L00Y* Jeff Wootton       */
/* REVISION: 8.6E     LAST MODIFIED: 06/03/98   BY: *J2JJ* Niranjan R.        */
/* REVISION: 9.0      LAST MODIFIED: 12/22/98   BY: *M02W* Luke Pokic         */
/* REVISION: 9.0      LAST MODIFIED: 03/13/99   BY: *M0BD* Alfred Tan         */
/* REVISION: 9.0      LAST MODIFIED: 04/25/00   BY: *L0WS* Reetu Kapoor       */
/* REVISION: 9.1      LAST MODIFIED: 08/13/00   BY: *N0KS* Mark Brown         */
/* REVISION: 9.1      LAST MODIFIED: 03/12/01   BY: *L16Y* Nikita Joshi       */
/* $Revision: 1.15 $    BY: Jean Miller          DATE: 04/15/02  ECO: *P05H*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/* Revision: EB2 SP3 GUI   BY: Kaine Zhang      DATE: 11/06/03   *hk-s-026*  */

/***********************************************************************
    Find all price lists that apply to the passed parameters and add them
    to a workfile.

    match_pt_um - indicates that only an exact match against the price
    list item and unit of measure is acceptable.

*/

/* I/O Definitions */

{mfdeclre.i}

define input  parameter pics_type       like pi_cs_type.
define input  parameter pics_code       like pi_cs_code.
define input  parameter part_type       like pi_part_type.
define input  parameter part_code       like pi_part_code.
define input  parameter price_par       like pih_parent.
define input  parameter price_feat      like pih_feature.
define input  parameter price_opt       like pih_option.
define input  parameter search_type     like pi_srch_type.
define input  parameter currency        like pi_curr.
define input  parameter price_um        like pi_um.
define input  parameter price_date      like pi_start.
define input  parameter match_pt_um     as logical.
define input  parameter price_site      like sod_site.
define input  parameter price_exch_rate like so_ex_rate.
define input  parameter price_exch_rate2 like so_ex_rate2.
define input  parameter price_nbr       like sod_nbr no-undo.
define input  parameter price_line      like sod_line no-undo.

define output parameter err_flag        as integer.

{pppivar.i}   /* Shared variables for pricing logic */

define variable all_token    like an_code       initial "qadall--+--+--+--+--+".
define variable l_no_disc    like mfc_logical   no-undo.
define variable l_confg_disc like pi_confg_disc no-undo.

define buffer anx_part for anx_det.

/* For use by gppibx03.p when processing */
first_pilist = yes.

/* Initialize freight list, since freight list is set by line */
if search_type = 2 then do:
   if price_par = "" and price_feat = "" and price_opt = "" then
      current_fr_list = "".   /*processing the parent, line level*/
end.

for each anx_det
fields (anx_active anx_code anx_node anx_type)
   where anx_type = pics_type
     and anx_node = pics_code
     and anx_active
no-lock:
   if anx_code <> pics_code then do:
      run p-pricing
         (input anx_det.anx_code,
          output err_flag).
   end.
end.

/* Check with customer code = customer */
run p-pricing
   (input pics_code,
    output err_flag).

/* Check with customer code = blank */
run p-pricing
   (input all_token,
    output err_flag).

PROCEDURE p-pricing:
   /* CHANGED THE NAME OF THE INPUT PARAMETER TO L_PICS_CODE     */
   /* FROM PICS_CODE FOR THE CASE WHERE THE DISCOUNT PRICE LIST  */
   /* HAS CUSTOMER NUMBER WITH BLANK ITEM NUMBER WHILE THE NET   */
   /* PRICE LIST HAS A BLANK CUSTOMER NUMNBER WITH ANALYSIS CODE */
   /* SPECIFIED FOR THE ITEM.                                    */

   define input  parameter l_pics_code     like pics_code no-undo.
   define output parameter err_flag        as integer no-undo.

   define buffer anxdet for anx_det.

   /* Look for part code = item */
/*hk-s-026*   {gppibx02.i  &pics_code = l_pics_code  */
/*hk-s-026*/  {xxgppibx02.i  &pics_code = l_pics_code
                &part_code = part_code}

   /* Check for less specific matches if allowed */
   if not match_pt_um then do:

      /* Look for part code = Analysis codes for item */
      for each anx_part where
               anx_part.anx_type = part_type
           and anx_part.anx_node = part_code
           and anx_active
      no-lock:
/*GUI*/ if global-beam-me-up then undo, leave.

         if anx_code <> part_code then do:
/*hk-s-026*           {gppibx02.i  &pics_code = l_pics_code  */
/*hk-s-026*/          {xxgppibx02.i  &pics_code = l_pics_code
                        &part_code = anx_part.anx_code}
         end.
      end.
/*GUI*/ if global-beam-me-up then undo, leave.


      /* Look for part code = blank */
/*hk-s-026*      {gppibx02.i  &pics_code = l_pics_code  */
/*hk-s-026*/     {xxgppibx02.i  &pics_code = l_pics_code
                   &part_code = all_token }

   end.

END PROCEDURE.  /* p-pricing */

/* CREATED P_PIMSTR TO CALL P_PIMSTR1 WITH DIFFERENT INPUT */
/* PARAMETERS BASED ON THE "OR" CONDITIONS PRESENT IN THE  */
/* CAN-FIND STATEMENTS IN THE PROGRAM GPPIBX2A.I           */

PROCEDURE p_pimstr:

   define input  parameter l_pics_code like pi_cs_code  no-undo.
   define input  parameter l_part_code like sob_part    no-undo.
   define input  parameter l_price_um  like pi_um       no-undo.
   define output parameter l_disc      like mfc_logical no-undo.

   run p_pimstr1
      (input l_pics_code,
       input l_part_code,
       input l_price_um,
       output l_disc).

   if not l_disc then
   run p_pimstr1
      (input l_pics_code,
       input all_token,
       input l_price_um,
       output l_disc).

   if not l_disc then
   run p_pimstr1
      (input all_token,
       input l_part_code,
       input l_price_um,
       output l_disc).

   if not l_disc then
   run p_pimstr1
      (input all_token,
       input all_token,
       input l_price_um,
       output l_disc).

   if not l_disc then
   run p_pimstr1
      (input l_pics_code,
       input l_part_code,
       input "",
       output l_disc).

   if not l_disc then
   run p_pimstr1
      (input l_pics_code,
       input all_token,
       input "",
       output l_disc).

   if not l_disc then
   run p_pimstr1
      (input all_token,
       input l_part_code,
       input "",
       output l_disc).

   if not l_disc then
   run p_pimstr1
      (input all_token,
       input all_token,
       input "",
       output l_disc).

END PROCEDURE.

PROCEDURE p_pimstr1:

   define input  parameter l_pics_code1 like pi_cs_code   no-undo.
   define input  parameter l_part_code1 like pi_part_code no-undo.
   define input  parameter l_price_um1  like pi_um        no-undo.
   define output parameter l_disc1      like mfc_logical  no-undo.
   define variable         l_part1      like pt_part      no-undo.

   if available qod_det then
      l_part1 = qod_det.qod_part.
   else
   if available sod_det then
      l_part1 = sod_det.sod_part.

   if can-find (first pt_mstr
                where pt_part    = l_part1
                  and pt_pm_code = "c")
   then do:
		/*hk-s-026*  add pi_user1 = .... */
      if can-find (first pi_mstr
         where pi_cs_type    = pics_type
         and pi_cs_code    = l_pics_code1
         and pi_part_type  = part_type
         and pi_part_code  = l_part_code1
         and pi_srch_type  = 2
         and pi_curr       = currency
         and pi_um         = l_price_um1
         and (pi_start     <= price_date
          or  pi_start     = ?)
         and (pi_expire    >= price_date
          or  pi_expire    = ?)
         and (pi_amt_type  = "3"
          or  pi_amt_type  = "4")
         and pi_confg_disc = l_confg_disc
         and pi_comb_type  = "1"
         and pi_user1 = price_site)
      then
         l_disc1 = yes.
   end. /* IF CAN-FIND (FIRST pt_mstr) */

   else do:
		/*hk-s-026*  add pi_user1 = .... */
      if can-find (first pi_mstr
         where pi_cs_type   = pics_type
         and pi_cs_code   = l_pics_code1
         and pi_part_type = part_type
         and pi_part_code = l_part_code1
         and pi_srch_type = 2
         and pi_curr      = currency
         and pi_um        = l_price_um1
         and (pi_start    <= price_date
          or  pi_start    = ?)
         and (pi_expire   >= price_date
          or  pi_expire   = ?)
         and (pi_amt_type = "3"
         or  pi_amt_type = "4")
         and pi_comb_type = "1"
         and pi_user1 = price_site)
      then
         l_disc1 = yes.

   end. /* ELSE CAN-FIND(first pt_mstr......) */

END PROCEDURE.
